<Workspace Version="1.3.4.6666" X="466.414737847793" Y="345.839874369379" zoom="0.663391956006523" ScaleFactor="100" Name="Home" Description="" RunType="Manual" RunPeriod="1000" HasRunWithoutCrash="False">
  <NamespaceResolutionMap />
  <Elements>
    <PythonNodeModels.PythonNode guid="617e9a23-d6bd-4cb9-8a05-4f39df72e1ff" type="PythonNodeModels.PythonNode" nickname="Python Script" x="393.417818523209" y="212.155615301318" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="true" inputcount="3">
      <PortInfo index="0" default="False" />
      <PortInfo index="1" default="False" />
      <PortInfo index="2" default="False" />
      <Script>import clr
import math
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *
from Autodesk.Revit.DB import MEPSystem
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore.List import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
clr.AddReference("System")
from System.Collections.Generic import List 
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.DB.Structure import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
 
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

famtype_co = UnwrapElement(IN[0])
famtype_rd = UnwrapElement(IN[1])

selection = uidoc.Selection
selection_ids = selection.GetElementIds()

elements = []
locations = []
classes = []
h = []

famtype_co.Activate()
famtype_rd.Activate()

TransactionManager.Instance.EnsureInTransaction(doc)

for element_id in selection_ids:
	elements.append(doc.GetElement(element_id))
	
if (elements[0].LookupParameter("Метод расчета по СО 153 343 21 122 2003").AsInteger()) == 1:

	for el in elements:	
		locations.append(el.Location.Point)
		classes.append(el.LookupParameter("Класс защиты по СО 153").AsInteger())
		h.append((el.LookupParameter("Высота для расчета").AsDouble())*304.8)
		
	line = Line.ByStartPointEndPoint(Point.ByCoordinates(locations[0][0], locations[0][1], locations[0][2]), Point.ByCoordinates(locations[1][0], locations[1][1], locations[1][2]))
	arrangepoint = Curve.PointAtParameter(line, 0.5)
	angle = math.degrees(math.atan((locations[1][1] - locations[0][1])/(locations[1][0] - locations[0][0])))
	angle_radian = math.atan((locations[1][1] - locations[0][1])/(locations[1][0] - locations[0][0]))
	len = ((((locations[1][1] - locations[0][1])**2) + ((locations[1][0] - locations[0][0])**2))**0.5)*304.8
	
	newobj = doc.Create.NewFamilyInstance(XYZ(arrangepoint.X, arrangepoint.Y, arrangepoint.Z),famtype_co,StructuralType.NonStructural)
	newobj.LookupParameter("L").Set(len/304.8)
	newobj.LookupParameter("Класс защиты").Set(classes[0])
	newobj.LookupParameter("h1").Set(h[1]/304.8)
	newobj.LookupParameter("h2").Set(h[0]/304.8)

	zaxis = Line.ByStartPointEndPoint((Point.ByCoordinates(arrangepoint.X*304.8, arrangepoint.Y*304.8, arrangepoint.Z*304.8)),(Point.ByCoordinates(arrangepoint.X*304.8, arrangepoint.Y*304.8, (arrangepoint.Z+100)*304.8))).ToRevitType()
	
else:
	
	for el in elements:	
		locations.append(el.Location.Point)
		classes.append(el.LookupParameter("Класс защиты по РД 34 А").AsInteger())
		h.append((el.LookupParameter("Высота для расчета").AsDouble())*304.8)
		
	line = Line.ByStartPointEndPoint(Point.ByCoordinates(locations[0][0], locations[0][1], locations[0][2]), Point.ByCoordinates(locations[1][0], locations[1][1], locations[1][2]))
	arrangepoint = Curve.PointAtParameter(line, 0.5)
	angle = math.degrees(math.atan((locations[1][1] - locations[0][1])/(locations[1][0] - locations[0][0])))
	angle_radian = math.atan((locations[1][1] - locations[0][1])/(locations[1][0] - locations[0][0]))
	len = ((((locations[1][1] - locations[0][1])**2) + ((locations[1][0] - locations[0][0])**2))**0.5)*304.8

	newobj = doc.Create.NewFamilyInstance(XYZ(arrangepoint.X, arrangepoint.Y, arrangepoint.Z),famtype_rd,StructuralType.NonStructural)
	newobj.LookupParameter("L").Set(len/304.8)
	newobj.LookupParameter("Класс защиты по РД 34 А").Set(classes[0])
	newobj.LookupParameter("h1").Set(h[1]/304.8)
	newobj.LookupParameter("h2").Set(h[0]/304.8)

	zaxis = Line.ByStartPointEndPoint((Point.ByCoordinates(arrangepoint.X*304.8, arrangepoint.Y*304.8, arrangepoint.Z*304.8)),(Point.ByCoordinates(arrangepoint.X*304.8, arrangepoint.Y*304.8, (arrangepoint.Z+100)*304.8))).ToRevitType()
	
TransactionManager.Instance.TransactionTaskDone()
Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, newobj.Id, zaxis, angle_radian)

OUT = newobj

#newobject.RevitDBDocument</Script>
    </PythonNodeModels.PythonNode>
    <DSRevitNodesUI.FamilyTypes guid="dfafab5c-3a4e-4ffa-a09a-f643ddd4a05b" type="DSRevitNodesUI.FamilyTypes" nickname="Family Types" x="-707.87394464078" y="136.176264358568" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" index="419:OBO_Тело защиты от двух молниеприемников СО 153_34.21.122_2003:OBO_Тело защиты от двух молниеприемников СО 153_34.21.122_2003" />
    <CoreNodeModels.Input.BoolSelector guid="3322ef26-09e1-4458-b57a-d16eacc99807" type="CoreNodeModels.Input.BoolSelector" nickname="Boolean" x="68.2017925515172" y="360.129336520721" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
      <System.Boolean>True</System.Boolean>
    </CoreNodeModels.Input.BoolSelector>
    <DSRevitNodesUI.FamilyTypes guid="c54c07e1-3b24-425e-8a82-e8b1baae1b79" type="DSRevitNodesUI.FamilyTypes" nickname="Family Types" x="-628.274036462921" y="236.208092428734" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" index="418:OBO_Тело защиты от двух молниеприемников РД 34.21.122_87:OBO_Тело защиты от двух молниеприемников РД 34.21.122_87" />
  </Elements>
  <Connectors>
    <Dynamo.Graph.Connectors.ConnectorModel start="dfafab5c-3a4e-4ffa-a09a-f643ddd4a05b" start_index="0" end="617e9a23-d6bd-4cb9-8a05-4f39df72e1ff" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="3322ef26-09e1-4458-b57a-d16eacc99807" start_index="0" end="617e9a23-d6bd-4cb9-8a05-4f39df72e1ff" end_index="2" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="c54c07e1-3b24-425e-8a82-e8b1baae1b79" start_index="0" end="617e9a23-d6bd-4cb9-8a05-4f39df72e1ff" end_index="1" portType="0" />
  </Connectors>
  <Notes />
  <Annotations />
  <Presets />
  <Cameras>
    <Camera Name="Фоновый просмотр" eyeX="139.087036132813" eyeY="308.509216308594" eyeZ="195.756149291992" lookX="80.7621994018555" lookY="-272.326934814453" lookZ="-150.688003540039" upX="0.336930394172668" upY="0.70090925693512" upZ="-0.628652632236481" />
  </Cameras>
</Workspace>